<?php 
if(KT!='KhiThe') exit;

class modules_model extends khithe_mysql{

	
	public function getmodules()
	{		
		$select = "SELECT * FROM ".modules." ORDER BY ID DESC";
		$result = parent::SelectMySQL($select);
		parent::CloseConnection();
		return $result; 
	}
	
	public function getmoduleID($ID){
		
		$ID = parent::checkStrMySQL($ID);
		$select = "SELECT * FROM ".modules." WHERE ID = '".$ID."'";
		$result= parent::SelectMySQL($select);
		parent::CloseConnection();
		return $result;
	}
	
	public function setCheckedmodule($ID,$Val)
	{
		$ID = parent::checkStrMySQL($ID);
		$update = "UPDATE ".modules." SET Status='".$Val."'  WHERE ID = '".$ID."' ";
		parent::CloseConnection();
		return parent::UpdateInsertMySQL($update);
	}
	
	public function delCheckedmodule($ID)
	{
		$ID = parent::checkStrMySQL($ID);
		$del = "DELETE FROM ".modules." WHERE ID='".$ID."' ";
		parent::CloseConnection();
		return parent::DeleteMySQL($del);
	}
	
	public function updateInsertmodule($_POST)
	{
		$ID = parent::checkStrMySQL($_POST['modulesID']);
		$modulename = parent::checkStrMySQL($_POST['txt_modulesName']);
		$module = parent::checkStrMySQL($_POST['txt_modules']);
		$app = parent::checkStrMySQL($_POST['txt_app_module']);
		
		if($_POST['acmodule']=='edit')
		{
			$query = "UPDATE ".modules." SET ModuleTitle='".$modulename."',ModuleDir='".$module."', AppName='".$app."' WHERE ID = '".trim($ID)."'";
		}
		
		else if($_POST['acmodule']=='add')
		{
			$query = "INSERT INTO ".modules."(ModuleTitle,ModuleDir,AppName,`Status`)VALUES('".$modulename."','".$module."','".$app."','true')";
		}
		
		parent::CloseConnection();
		return parent::UpdateInsertMySQL($query);
		
	}
}
?>